package com.sitc.street_lab_2013;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

public class LocationsListViewActivity extends ListActivity {

	private ArrayList<String> locations;
	private ArrayList<SitcLoc> ref;
	private ListView lv;

	/** Called when the activity is first created. */
	@SuppressLint("NewApi")
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.locations_listview);

		locations = new ArrayList<String>();
		ref = new ArrayList<SitcLoc>();
		getLocations();
		
//		ListView list = (ListView) findViewById(R.id.loc_listView);
//		ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), 
//				R.layout.listview_item, locations);
//		list.setAdapter(adapter);
		
		this.getActionBar().setTitle("Location Selection");
		
		LocationsListviewAdapter adapter = new LocationsListviewAdapter(this, ref.toArray());
		
		setListAdapter(adapter);
		
//		list.setOnItemClickListener(new OnItemClickListener() {
//
//			@Override
//			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
//					long arg3) {
//				
//				Intent locationIntent = new Intent(LocationsListViewActivity.this, MapViewActivity.class);
//				
//				// If first in list, "Show all Locations", do not pass location
//				if(arg2!=0) {
//					
//				locationIntent.putExtra("location", ref.get(arg2));
//				
//				}
//				
//				LocationsListViewActivity.this.startActivity(locationIntent);
//			}
//
//		});
	}

	
	
	
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		Intent locationIntent = new Intent(LocationsListViewActivity.this, MapViewActivity.class);
		
		// If first in list, "Show all Locations", do not pass location
		if(position!=0) {
			
		locationIntent.putExtra("location", ref.get(position));
		
		}
		
		LocationsListViewActivity.this.startActivity(locationIntent);
	}




	private void getLocations() {
		ref = LocConstants.populate();
		for(SitcLoc l : ref) {
			locations.add(l.getLocName());
		}
	}

}
